import {
	http
} from '@/service/index.js'
import store from '@/store/index.js'
import configs from '@/config/index.js'

import utils from '@/utils/time.js'

function RndNum(n) {
	var rnd = "";
	for (var i = 0; i < n; i++)
		rnd += Math.floor(Math.random() * 10);
	return rnd;
}


// 获取注册验证码 mobilePhone
export const getSignature = async () => {
	return await http.post(`/system/fileupload/getSignature`, {
		dir: 'img'
	})
}

export const uploadImg = async (url) => {
	console.log('ceshi', url)
	const res = await getSignature();
	console.log(res)
	const index1 = url.lastIndexOf(".");
	const index2 = url.length;
	const type = url.substring(index1, index2);
	const key = 'img/product/' + utils.formatTime(false, 'YYYYMMDD') + '/' + RndNum(10) + '.png'
	const resp = await uni.uploadFile({
		url: res.host,
		name: 'file',
		filePath: url,
		formData: {
			OSSAccessKeyId: res.accessid,
			policy: res.policy,
			Signature: res.signature,
			key,
			success_action_status: '200'
		}
	});
	if (!resp[0]) {
		return res.host + '/' + key
	} else {
		return ''
	}

}


export const groupItemListByKey = async (data) => {
	console.log(data)
	return await http.get(`/system/typegroup/groupItemListByKey`, {
		groupCodes: data
	})
}

export const addAppError = async (data) => {
	return await http.post(`/log/apperror/add`, data)
}
